const masterMind = (solution, guess) => {
  let m = 0, n = 0,
    obj = {
      'R': 0,
      'G': 0,
      'B': 0,
      'Y': 0
    };
  for (let i = 0; i < 4; i++) {
    if (solution[i] === guess[i]) {
      m++
    } else {
      if (obj[solution[i]]++ < 0) n++
      if (obj[guess[i]]-- > 0) n++
    }
  }
  return [m, n]
}

console.log(masterMind('RGBY', 'GGRR'));